package com.ruoyi.wechat.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.BusinessWechat;
import com.ruoyi.wechat.service.IBusinessWechatService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 微信推送Controller
 *
 * @author ruoyi
 * @date 2022-08-29
 */
@RestController
@RequestMapping("/wechat/wechat")
public class BusinessWechatController extends BaseController
{
    @Autowired
    private IBusinessWechatService businessWechatService;

    /**
     * 查询微信推送列表
     */
    @PreAuthorize("@ss.hasPermi('wechat:wechat:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessWechat businessWechat)
    {
        startPage();
        List<BusinessWechat> list = businessWechatService.selectBusinessWechatList(businessWechat);
        return getDataTable(list);
    }

    /**
     * 导出微信推送列表
     */
    @PreAuthorize("@ss.hasPermi('wechat:wechat:export')")
    @Log(title = "微信推送", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessWechat businessWechat)
    {
        List<BusinessWechat> list = businessWechatService.selectBusinessWechatList(businessWechat);
        ExcelUtil<BusinessWechat> util = new ExcelUtil<BusinessWechat>(BusinessWechat.class);
        util.exportExcel(response, list, "微信推送数据");
    }

    /**
     * 获取微信推送详细信息
     */
    @PreAuthorize("@ss.hasPermi('wechat:wechat:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(businessWechatService.getById(id));
    }

    /**
     * 新增微信推送
     */
    @PreAuthorize("@ss.hasPermi('wechat:wechat:add')")
    @Log(title = "微信推送", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessWechat businessWechat) {
        return toAjax(businessWechatService.save(businessWechat));
    }

    /**
     * 修改微信推送
     */
    @PreAuthorize("@ss.hasPermi('wechat:wechat:edit')")
    @Log(title = "微信推送", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessWechat businessWechat) {
        return toAjax(businessWechatService.updateById(businessWechat));
    }

    /**
     * 删除微信推送
     */
    @PreAuthorize("@ss.hasPermi('wechat:wechat:remove')")
    @Log(title = "微信推送", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(businessWechatService.removeByIds(Arrays.asList(ids)));
    }

    /**
     * 批量登录
     */
    @PostMapping("/push")
    public AjaxResult push()
    {
        businessWechatService.push();
        return AjaxResult.success();
    }
}
